import type {ApiResponse, PageResult} from "../../utils/ApiResponse";
import {Article, PageArticle} from "./types/article.dto.ts";
import http from "../../utils/http";

export const getAllArticles = (data: PageArticle): Promise<PageResult<Object>> => {
  return http.get(`/articles/info`, {
    params: {
      page: data.page,
      limit: data.limit,
      title: data.title,
      categoryId: data.categoryId,
    }
  })
};

export const getArticleById = (data: number): Promise<ApiResponse<Article>> => {
  return http.get(`/articles/info/${data}`);
};

export const createArticle = (data: Article): Promise<ApiResponse<Object>> => {
  return http.post(`/articles/save`, data);
};

export const updateArticle = (data: Article): Promise<ApiResponse<Object>> => {
  return http.put(`/articles/save`, data);
};

export const deleteArticle = (id: number): Promise<ApiResponse<Object>> => {
  return http.delete(`/articles/delete/${id}`);
};

// 获取分类列表
export const getCategoryList = (): Promise<ApiResponse<Array<Object>>> => {
  return http.get(`/categories/list`);
};